﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Dynamic;using System.Text;
using System.Data;
using System.Data.Linq;
using System.Transactions;
using LinqToSqlExtensions;using System.ServiceModel;
using System.Collections;
using System.Collections.Generic;
using CardsServer.DAL;
using CardsServer.Tools;
namespace CardsServer.WCF
{
    public partial interface IService
    {
        [OperationContract]
        List<View_wsd_all> wsd_get_By_date(DateTime? sd, DateTime? ed, int ACID);

        [OperationContract]
        List<wsd> wsd_get_By(int? dlsid, DateTime? sd, DateTime? ed, string jrh, string yhmc,int? state, int ACID);

        [OperationContract]
        List<View_wsd_0> View_wsd_0_get(int? dlsid, DateTime? sd, DateTime? ed, string jrh, string yhmc,  int ACID);

        [OperationContract]
        List<View_wsd_all> wsd_get_By_ldr(Guid ldr, int ACID);
    }
    public partial class Service : IService
    {
        public List<wsd> wsd_get_By(int? dlsid, DateTime? sd, DateTime? ed, string jrh, string yhmc,int? state, int ACID)
        {
            using (CardsServer.DAL.DataClassesDataContext ctx = new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
            {
                Expression<Func<wsd, bool>> predicate = PredicateBuilder.True<wsd>();
                if (sd != null && ed != null)
                {
                    predicate = predicate.And(p => p.Pdate >= sd && p.Pdate <= ed);
                }
                if (dlsid != null)
                {
                    predicate = predicate.And(p => p.dlsid == dlsid);
                }
                if (!string.IsNullOrEmpty(jrh))
                {
                    predicate = predicate.And(p => p.jrh == jrh);
                }
                if (!string.IsNullOrEmpty(yhmc))
                {
                    predicate = predicate.And(p => p.yhmc == yhmc);
                }
                if (state!=null)
                {
                    predicate = predicate.And(p => p.state == state);
                }
                return ctx.wsd.Where(predicate).ToList();
            }
        }
        public List<View_wsd_0> View_wsd_0_get(int? dlsid, DateTime? sd, DateTime? ed, string jrh, string yhmc,  int ACID)
        {
            using (CardsServer.DAL.DataClassesDataContext ctx = new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
            {
                Expression<Func<View_wsd_0, bool>> predicate = PredicateBuilder.True<View_wsd_0>();
                if (sd != null && ed != null)
                {
                    predicate = predicate.And(p => p.Pdate >= sd && p.Pdate <= ed);
                }
                if (dlsid != null)
                {
                    predicate = predicate.And(p => p.dlsid == dlsid);
                }
                if (!string.IsNullOrEmpty(jrh))
                {
                    predicate = predicate.And(p => p.jrh == jrh);
                }
                if (!string.IsNullOrEmpty(yhmc))
                {
                    predicate = predicate.And(p => p.yhmc == yhmc);
                }
                return ctx.View_wsd_0.Where(predicate).ToList();
            }
        }

        public List<View_wsd_all> wsd_get_By_date(DateTime? sd, DateTime? ed,  int ACID)
        {
            using (CardsServer.DAL.DataClassesDataContext ctx = new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
            {
                Expression<Func<View_wsd_all, bool>> predicate = PredicateBuilder.True<View_wsd_all>();
                if (sd != null && ed != null)
                {
                    predicate = predicate.And(p => p.开单日期 >= sd && p.开单日期 <= ed);
                }

                return ctx.View_wsd_all.Where(predicate).ToList();
            }
        }

        public List<View_wsd_all> wsd_get_By_ldr(Guid ldr, int ACID)
        {
            using (CardsServer.DAL.DataClassesDataContext ctx = new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
            {
                return ctx.get_wsd_all(ldr).ToList();
            }
        }
    }
}

